<?php
/**
 * Created by PhpStorm.
 * User: steven
 * Date: 2017/11/12
 * Time: 下午8:33
 */

namespace app\api\controller\v1;

use app\api\validate\IDMustBePostiveInt;
use app\api\model\Banner as BannerModel;
use app\lib\exception\BannerMissException;
use think\Exception;


class Banner {
    /**
     *
     * 获取指定id的banner信息
     * @url /banner/:id
     * @http GET
     * @id banner 的id号
     *
     **/
    public function getBanner($id){

        // 独立验证 (这段代码是独立验证)
        // 验证器
        // 验证器比独立验证做了一个更好的封装

        (new IDMustBePostiveInt())->goCheck();
        $banner = BannerModel::getBannerByID($id);
        if(!$banner){
            throw new BannerMissException();
        }
        return $banner;
    }
}